package com.cx.base.day19_thread;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author: robert.song
 * @Date: Created in 2021/7/29
 */
@Slf4j(topic = "c.Thread_2_Method_Interrupt")
public class Thread_2_Method_Interrupt {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            log.debug("sleep...");
            System.out.println("sleep...");
            try {
                Thread.sleep(5000); //包括wait,join这些方法，发生打断时打断标记会被清除
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t1");
        t1.start();
//        保证t1线程进入sleep
        try {
            t1.join(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("interrupt");
        t1.interrupt();
        System.out.println("打断标记：" + t1.isInterrupted());
    }
}
